import sys
import pandas as pd
from utils.translateAPI import *
import time

if __name__ == "__main__":

    translater = BaiduTranslate('zh','en')

    sheet = pd.read_excel('./testPro/output/'+sys.argv[1]+'.xlsx', engine='openpyxl',sheet_name=0)

    CacheM = {}

    for label, ser in sheet['Usescenes'].items():
        temp = (False, '')
        ser = str(ser)
        if ser in CacheM.keys():
            sheet.loc[label, 'Usescenes(machine translation)'] = CacheM[ser]
        else:
            while not temp[0]:
                temp = translater.BdTrans(ser)
                print(temp)
                time.sleep(1)

            sheet.loc[label, 'Usescenes(machine translation)'] = temp[1]
            CacheM.update({ser:temp[1]})

    sheet.to_excel('./testPro/output/'+sys.argv[1]+'.xlsx',index=False)
